import { DefaultContext } from "koa";

// 放过options
export default async(ctx: DefaultContext, next: () => Promise<any>) => {
    ctx.compress = true; // 默认就开启压缩
    ctx.set("Access-Control-Allow-Origin", "*");
    ctx.set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild");
    ctx.set("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS");
    if (ctx.method == "OPTIONS") {
        ctx.body = 200;
    } else {
        await next();
    }
};
